# 文件读写

file = open("students.txt", encoding="utf-8").readlines()

# readlines  返回一个列表  每一行后面会多一个\n
for line in file:
    # strip  去掉前后空格
    print(line.strip())

lines = [line.strip().split(",") for line in file]
for line in lines:
    print(line)

'''
mode  默认r
w 覆盖写
a追加


'''

a = open("a.txt", mode="a")

l = ["java", "shujia", "python"]

for i in l:
    a.write(i)
    a.write("\n")

a.close()

# 简写，自动关闭io流对象
with open("students.txt", encoding="utf-8") as f:
    lines = [line.strip() for line in f.readlines()]
    print(lines)

with open("a.txt", mode="r") as f:
    print(f.read(10))
